/**
 * Project Name:cnsy-url-short-service
 * File Name:SysUserLoginLogServiceImpl.java
 * Package Name:cn.cnsy123.shorturls.business.service.impl 
 * Date: 2020年4月25日-上午11:33:02
 * Copyright (c) 2020, yangpengfei@360@126.com All Rights Reserved. 
 *
 */

package cn.cnsy123.shorturls.business.service.impl;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import cn.cnsy123.shorturls.business.entity.SysUserLoginLogInfo;
import cn.cnsy123.shorturls.business.exception.BusinessException;
import cn.cnsy123.shorturls.business.mapper.SysUserLoginLogInfoMapper;
import cn.cnsy123.shorturls.business.service.SysUserLoginLogService;

/**
 * ClassName: SysUserLoginLogServiceImpl
 * 
 * @author yangpengfei
 * @date 2020年4月25日-上午11:33:02
 * @version 1.0
 * @since JDK 1.7
 */
@Service
public class SysUserLoginLogServiceImpl implements SysUserLoginLogService {
    
    private static final Logger logger = LoggerFactory.getLogger(SysUserLoginLogServiceImpl.class);
    
    @Autowired
    private SysUserLoginLogInfoMapper sysUserLoginLogInfoMapper;

    @Override
    @Async
    @Transactional(readOnly = false,propagation = Propagation.REQUIRED,rollbackFor = BusinessException.class)
    public void saveUserLoginLog(String userName, String realName, String loginIp, String deviceType, String browserName,
            Date loginTime) {
        try {
            SysUserLoginLogInfo record = new SysUserLoginLogInfo();
            record.setUserName(userName);
            record.setLoginIp(loginIp);
            record.setLoginTime(loginTime);
            record.setBrowserName(browserName);
            record.setDeviceType(deviceType);
            sysUserLoginLogInfoMapper.insertSelective(record);
            logger.info("登录记录保存成功");
        } catch (Exception e) {
            logger.error("发生异常",e);
        }
    }

}
